/*
 * ListTempera.java
 *
 * Created on __DATE__, __TIME__
 */

package com.ruif.view;

import javax.swing.JOptionPane;

import com.ruif.client.TemperaServiceImpl;
import com.ruif.model.Tempera;
import com.ruif.service.ITemperaService;
import com.ruif.util.DBUtil;

/**
 *
 * @author __USER__
 */
public class AddTemperaFrame extends javax.swing.JInternalFrame
{
	ITemperaService temService = new TemperaServiceImpl();
	DBUtil dbUtil = new DBUtil();

	private static final long serialVersionUID = -1336761306424610231L;

	/** Creates new form ListTempera */
	public AddTemperaFrame()
	{
		initComponents();
		this.setLocation(200, 50);
	}

	// GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	@SuppressWarnings({ "rawtypes", "unchecked" })
    private void initComponents()
	{

		jLabel1 = new javax.swing.JLabel();
		jTextField_temp = new javax.swing.JTextField();
		jButton_add = new javax.swing.JButton();
		jLabel2 = new javax.swing.JLabel();
		jComboBox_status = new javax.swing.JComboBox();
		jButton_reset = new javax.swing.JButton();

		setClosable(true);
		setIconifiable(true);
		setTitle("\u65b0\u589e\u6e29\u5ea6\u8bb0\u5f55");

		jLabel1.setText("\u6e29  \u5ea6\uff1a");

		jButton_add.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\pc\\桌面\\Images\\add.png")); // NOI18N
		jButton_add.setText("\u65b0\u589e");
		jButton_add.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				jButton_addActionPerformed(evt);
			}
		});

		jLabel2.setText("\u72b6  \u6001\uff1a");
		jComboBox_status.setModel(new javax.swing.DefaultComboBoxModel(new String[]
		{ "正常", "报警" }));
		jButton_reset.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\pc\\桌面\\Images\\reset.png")); // NOI18N
		jButton_reset.setText("\u91cd\u7f6e");
		jButton_reset.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				jButton_resetActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				javax.swing.GroupLayout.Alignment.TRAILING,
				layout.createSequentialGroup().addContainerGap(50, Short.MAX_VALUE)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
								.addGroup(layout.createSequentialGroup().addComponent(jButton_add)
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
										.addComponent(jButton_reset, javax.swing.GroupLayout.PREFERRED_SIZE, 81,
												javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGroup(layout.createSequentialGroup()
										.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(jLabel1).addComponent(jLabel2))
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(layout
												.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
												.addComponent(jComboBox_status,
														javax.swing.GroupLayout.Alignment.LEADING, 0,
														javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
												.addComponent(jTextField_temp,
														javax.swing.GroupLayout.Alignment.LEADING,
														javax.swing.GroupLayout.PREFERRED_SIZE, 155,
														javax.swing.GroupLayout.PREFERRED_SIZE))))
						.addGap(54, 54, 54)));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
				.createSequentialGroup().addGap(27, 27, 27)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
						.addComponent(jTextField_temp, javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
						.addComponent(jComboBox_status, javax.swing.GroupLayout.PREFERRED_SIZE,
								javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
						.addComponent(jButton_add).addComponent(jButton_reset, javax.swing.GroupLayout.PREFERRED_SIZE,
								24, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addGap(37, 37, 37)));

		pack();
	}// </editor-fold>
		// GEN-END:initComponents

	private void jButton_resetActionPerformed(java.awt.event.ActionEvent evt)
	{
		resetValue();
	}

	/**
	 * 触发 Tempera 新增功能
	 * @param evt
	 */
	private void jButton_addActionPerformed(java.awt.event.ActionEvent evt)
	{
		String temp = this.jTextField_temp.getText().trim();
		int status = this.jComboBox_status.getSelectedIndex();

		Tempera tem = new Tempera(Integer.parseInt(temp), status);

	    int ok = temService.add(tem);
		if (ok == 1)
		{
		    JOptionPane.showMessageDialog(null, "新增成功！");
		    resetValue();
		}
		else
		{
			JOptionPane.showMessageDialog(null, "新增失败！");
			return;
		}
	}

	/**
	 * 重置事件处理
	 */
	public void resetValue()
	{
		this.jTextField_temp.setText("");
		this.jComboBox_status.setSelectedItem("正常");
	}

	// GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton_add;
	private javax.swing.JButton jButton_reset;
	@SuppressWarnings("rawtypes")
    private javax.swing.JComboBox jComboBox_status;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JTextField jTextField_temp;
	// End of variables declaration//GEN-END:variables

}
